package com.gs.core.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
@DiscriminatorValue(value="USER")
public class User extends Person {
	private String departmentCode;
	private User boss;
	private List<Vendor> vendors = new ArrayList<Vendor>();
	
	public User() {
	}
	
	private User(String firstName, String lastName,String departmentCode, User boss){
		this.firstName = firstName;
		this.lastName = lastName;
		this.departmentCode = departmentCode;
		this.boss = boss;
	}
	
	public static User create(String firstName, String lastName,String departmentCode, User boss){
		return new User(firstName,lastName,departmentCode, boss);
	}
	
	@Column(name="DEPT_CODE")
	public String getDepartmentCode() {
		return departmentCode;
	}
	public void setDepartmentCode(String departmentCode) {
		this.departmentCode = departmentCode;
	}
	
	public void addBoss(User user){
		this.boss = user;
	}
	
	public void addVendor(Vendor v){
		this.vendors.add(v);
	}
	
	@ManyToOne
	@JoinColumn(name="BOSS_ID")
	public User getBoss() {
		return boss;
	}
	public void setBoss(User boss) {
		this.boss = boss;
	}

	@OneToMany(cascade=CascadeType.ALL,orphanRemoval=true)
    @JoinColumn(name="CLIENT_ID")
	public List<Vendor> getVendors() {
		return vendors;
	}

	public void setVendors(List<Vendor> vendors) {
		this.vendors = vendors;
	}
	
	
}
